<template>
  <div class="user-manage innerPageTable-out-flex">
    <div v-if="showNoPowerTip">
      <Exception></Exception>
    </div>
    <div v-if="!showNoPowerTip">
      <search-form
        @search="searchHandle"
        @reset="resetHandle"
        :label-width="170"
        :form-data="formData"
      ></search-form>

      <InnerPageTable ref="listTable" :config="pageTableConfig">
        <div slot="table-bar">
  <!--        <Button @click.native="exportHandle()">导出</Button>-->
          <Button @click.native="addHandle">新建</Button>
        </div>
      </InnerPageTable>
    </div>
  </div>
</template>

<script>
import SearchForm from "@/components/common/SearchForm";
import { mixin } from "@/views/superviseInfo/mix/mixin";
import { configForm, generateColumns } from './constant'
import { superviseInfoAPI } from "@api/superviseInfo";
import DispatchConfigEditor from "@/views/dispatch-config/dispatchConfigEditor";
import Exception from "./exception";

export default {
  name: "DispatchConfigIndex",
  mixins: [mixin],
  components: {
    SearchForm,
    DispatchConfigEditor,
    Exception
  },
  computed: {
    searchData() {
      return configForm.bind(this)()
    },
    showNoPowerTip() {
      // 系统管理员才有权限
      const roleList = ['5']
      return !this.currentRole.split(',').some(item => roleList.includes(item))
    }
  },
  data() {
    return {
      pageTableConfig: {
        loadDataFn: this.getTableList,
        columns: generateColumns.bind(this)(),
        initParam: {
          startDate: 0,
          endDate: 0
        },
        autoFirst: true,
      },
      selectData: []
    }
  },
  methods: {
    getTableList(tableObj) {
      let { responseProcess, param, initParam } = tableObj;
      const params = {
        ...initParam,
        ...param
      }
      superviseInfoAPI.getDispatchConfigList(params).then(res => {
        responseProcess(res.data);
      })
    },
    dataStateHandle(h, row) {
      return h('span', {
        class: {
          green: row.dataState == 1,
          grey: row.dataState == 0
        }
      },
      [
        h('span',
          {
            class: 'circle',
          }
        ),
        row.dataState == 1 ? '生效中' : '已完成'
      ])
    },
    addHandle() {
      new this.$pageModal(
        DispatchConfigEditor,
        {
          props: {
            handleType: 'add'
          }
        },
        () => {
          this.searchHandle();
        }
      );
    },
  }
};
</script>

<style scoped>

</style>
